<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
    <meta content="featon inc." name="author">
    <link href="/static/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/vendor/bootstrap/css/bootstrap-theme.min.css" rel="stylesheet">
    <link href="/static/vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="/static/vendor/jqPagination/css/jqpagination.css" rel="stylesheet">
    <link href="/static/vendor/datetimepicker/jquery.datetimepicker.css" rel="stylesheet">
    <link href="/static/vendor/skin/ftskin.css" rel="stylesheet">
    <title>企业信息</title>
    <style>
        #page .pagination a {
            height: auto;
            width: 50px;
        }

    </style>
</head>
<body>
<div class="ft-subpage-wrapper container-fluid">
    <div class="row">
        <div class="col-lg-12">
            <div class="tools-box">
                <div class="form-inline">
                    <div class="form-group">
                        <a class="btn" href="/ci/companyList" style="font-size: 22px"><i class="glyphicon glyphicon-menu-left"></i>返回</a>
                        <button class="btn btn-info" onclick="publicSelectCheckbox(table,'qyId','enable()');"
                                type="button"><span
                                aria-hidden="true" class="glyphicon glyphicon-edit"></span> 启用
                        </button>
                        <button class="btn btn-danger" onclick="publicSelectCheckbox(table,'qyId','deactivate()');"
                                type="button"><span
                                aria-hidden="true" class="glyphicon glyphicon-remove"></span> 停用
                        </button>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn" href="/cp/isDeleteCompany" style="font-size: 18px"><i class="glyphicon glyphicon-refresh"></i>刷新</a>
                    </div>

                    <span style="float:right;">
			<table border="0" cellpadding="0" cellspacing="0" style="text-align:left;padding-right:5px;float:right">
				<tr>
					<td width="195">
						<div class="input-group">
							<input class="form-control" id="searchText" placeholder="关键字" type="text">
							<span class="input-group-btn">
								<button class="btn btn-info" id="search" type="button"><span aria-hidden="true"
                                                                                             class="glyphicon glyphicon-search"></span> 查询</button>
							</span>
						</div>
					</td>
				</tr>
			</table>
          </span>
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12" id="table">
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="container-fluid">
            <div id="turn">

            </div>
        </div>
    </div>
    <!-- /.row 证书-->
</div>
<script src="/static/vendor/jquery/jquery-3.3.1.min.js"></script>
<script src="/static/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="/static/vendor/jqPagination/js/jquery.jqpagination.min.js"></script>
<script src="/static/vendor/skin/js/ft-ui.js"></script>
<script src="/static/vendor/skin/js/table-common.js"></script>
<script src="/static/vendor/skin/js/java.js"></script>
<script src="/static/vendor/skin/js/jquery.c.js"></script>
<script>
    var tp = new TurnPage();
    var table = new Table();
    table.table_name = "table_list";
    var resultList = null;
    var beanList = null;
    var con_map = new Map();
    tp.setPageSize(10)

    $("ul").on("click", "li", function () {
        tp.curr_page = $(this).text()
        $(this).addClass("active")
        $(this).siblings().removeClass("active")
        loadListble()
    })


    function initTable() {
        var colsMap = new Map();
        var colsList = new List();
        colsList.add(setTitleClos("serialNumber", "序号", "40px", "", "", ""));
        colsList.add(setTitleClos("code", "企业编号", "70px", "", "", ""));//英文名，显示名，宽，高，样式名，点击事件　
        colsList.add(setTitleClos("name", "企业名称", "70px", "", "", ""));//英文名，显示名，宽，高，样式名，点击事件　
        colsList.add(setTitleClos("legalMan", "法人（负责人）", "100px", "", "", ""));
        colsList.add(setTitleClos("phone", "联系电话", "70px", "", "", ""));
        colsList.add(setTitleClos("action", "&nbsp;&nbsp;&nbsp;状态", "100px", "", "", 'changeState()'));
        //table.checkBox = false;
        table.setColsList(colsList);
        table.setAllColsList(colsList);
        table.enableSort = false;//禁用表头排序
        table.onSortChange = showList;
        table.show("table");//里面参数为外层div的id
    }

    function loadListble() {
        tp.curr_page = 1;
        showList();
        showTurnPage();
    }

    function showList() {
        con_map.put("start_num", parseInt(tp.getStart()));
        con_map.put("page_size", parseInt(tp.pageSize));
        resultList = top.ajax.synclBody("/ci/getIsDeleteListByPage", con_map.toJSON())
        beanList = resultList.companies;
        curr_bean = null;
        table.setBeanList(beanList, "td_list");//设置列表内容的样式
        table.show("table");

        tp.setTotal(resultList.count)
        table.getCol("action").each(function (i) {
            if (i > 0) {
                // $(this).html('<a href="javascript:openUpdatePage(\'' + beanList[i - 1].qyId + '\')">编辑</a>&nbsp;&nbsp;<a href="javascript:deleteSingleObject(\'' + beanList[i - 1].qyId + '\')">删除</a>');
                $(this).html(`
                <a  href="javascript:changeState(` + beanList[i - 1].qyId +`)">
                <div status="` + beanList[i - 1].isDelete +`" class="btn isDeleteBtn" id="` + beanList[i - 1].qyId + `" style="font-weight: 900;padding: 0 1px;width: auto;height: 24px;border-radius: 12px;box-shadow: 0 0 6px inset;
                        border: 3px solid #30add3; background: #2b2a2a;"><p  style="float: right;color: red;">已停用</p>
                            <span style="width: 20px;height: 20px;background-color: #00a2d4;
                              background-image: radial-gradient( white,black); display: inline-block;float: left; border-radius: 50%;font-size: 12px"></span>
                        </div>
                        </a>
                `);
            }
        });
        table.getCol("serialNumber").each(function (i) {
            if (i > 0) {
                $(this).html(`<span style="font-weight: bold">`+i+`</span>`);
            }
        });
        table_input_init(table.table_name);
    }

    jQuery(function ($) {
        initTable();
        loadListble()
        let total = tp.getTotal();
        let pageSize = tp.getPageSize();
        let countPage = Math.ceil(parseInt(total) / parseInt(pageSize));
        for (let i = 1; i <= countPage; i++) {
            if (i === 1) {
                $("#next").before(`<li  class="active"><a href="JavaScript:">` + i + `</a></li>`)
            } else {
                $("#next").before(`<li ><a href="JavaScript:">` + i + `</a></li>`)
            }
        }
    });

    function showTurnPage(){
        tp.total = tp.getTotal()
        tp.show("turn","");
        tp.onPageChange = showList;
    }

    function enable(qyId) {
        var sel_id = '';
        if (qyId != '' && qyId != null) {
            sel_id = qyId;
        } else
            sel_id = table.getSelecteCheckboxValue("qyId");
        var dm = new Map();
        dm.put("qyId", sel_id);
        if (top.ajax.synclBody('/ci/enable', dm.toJSON())) {
            changeStateCss(sel_id, 0);
            modelWindow.alert("用户信息" + top.CMSLang.Set_success);
        } else {
            modelWindow.error("用户信息" + top.CMSLang.Set_fail);
        }
    }

    function deactivate(qyId) {
        var sel_id = '';
        if (qyId != '' && qyId != null) {
            sel_id = qyId;
        } else
            sel_id = table.getSelecteCheckboxValue("qyId");
        var dm = new Map();
        dm.put("qyId", sel_id);
        if (top.ajax.synclBody('/ci/deteleCompany', dm.toJSON())) {
            changeStateCss(sel_id, -1);
            modelWindow.alert("用户信息" + top.CMSLang.Set_success);
        } else {
            modelWindow.error("用户信息" + top.CMSLang.Set_fail);
        }
    }

    function changeState(qyId) {
        let status = $("#" + qyId).attr("status");
        if (status === '0') {
            deactivate(qyId);
        }
        if (status === '-1') {
            enable(qyId);
        }
    }

    function changeStateCss(qyId, status) {
        let ids = qyId.toString().split(",");
        for (let id of ids) {
            let that = $("#" + id);
            let float = $(that).children("span").css("float");
            if (status === -1) {
                $(that).children("span").css("float", 'left');
                $(that).children("p").css({'float': 'right', 'color': 'red'});
                $(that).children("p").text('已停用');
                $(that).css("backgroundColor", '#2b2a2a')
            }
            if (status === 0) {
                $(that).children("span").css("float", 'right');
                $(that).children("p").css({'float': 'left', 'color': 'wheat'});
                $(that).children("p").text('已启用');
                $(that).css("backgroundColor", '#5b5bdc')
            }
        }
    }


    /*todo   查询*/
    $("#search").click(function () {
        let val = $("#searchText").val();
    })
</script>

</body>
</html>
